package com.xiaowen.projectDataTitle.controller;

import cn.hutool.core.util.ObjectUtil;
import com.xiaowen.project.entity.Project;
import com.xiaowen.projectDataTitle.dto.ProjectDataColumn;
import com.xiaowen.projectDataTitle.dto.ProjectDataTitleDTO;
import com.xiaowen.projectDataTitle.entity.ProjectDataTitle;
import com.xiaowen.projectDataTitle.service.ProjectDataTitleService;
import com.xiaowen.tool.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 项目数据列表 前端控制器
 * </p>
 *
 * @author yf-wenhao
 * @since 2024-09-30
 */
@RestController
@RequestMapping("/projectDataTitle")
public class ProjectDataTitleController {

    @Autowired
    private ProjectDataTitleService projectDataTitleService;

    /**
     * 获取文件头list
     * @return the result
     * @author hero
     * @date 2024 -09-18 14:25:04
     */
    @PostMapping("/getHeadList")
    public Result<List<String>> getHeadList(@RequestParam("importFile") MultipartFile importFile, Integer projectId) {
        if (ObjectUtil.isEmpty(importFile) || ObjectUtil.isEmpty(projectId)){
            return new Result<>();
        }
        List<String> headList = projectDataTitleService.getHeadList(importFile, projectId);
        return new Result<List<String>>().ok(headList);
    }

    @PostMapping("/setUp/projectData/column")
    public Result<Boolean> setUpProjectDataColumn(@RequestBody ProjectDataColumn projectDataColumn) {
        if (ObjectUtil.isEmpty(projectDataColumn) || ObjectUtil.isEmpty(projectDataColumn.getIdColumn())
                || ObjectUtil.isEmpty(projectDataColumn.getProjectId()) || ObjectUtil.isEmpty(projectDataColumn.getOriginalWordColumn())){
            return new Result<>();
        }
        projectDataTitleService.setUpProjectDataColumn(projectDataColumn);
        return new Result<Boolean>().ok(true);
    }

    /**
     * 查询详情
     * @param projectId the id
     * @return the result
     * @author hero
     * @date 2024 -09-18 14:25:03
     */
    @GetMapping(value = "/queryByProjectId/{projectId}")
    public Result<ProjectDataTitleDTO> queryProjectDataTitleByProjectId(@PathVariable Integer projectId) {
        return new Result<ProjectDataTitleDTO>().ok(projectDataTitleService.queryProjectDataTitleByProjectId(projectId));
    }
}
